package com.qfedu.yanglao20admin.plancase.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.common.annotation.LogInfo;
import com.qfedu.yanglao20.entity.plancase.CaseType;
import com.qfedu.yanglao20admin.plancase.param.CaseTypeParam;
import com.qfedu.yanglao20admin.plancase.service.CaseTypeService;
import com.qfedu.yanglao20admin.plancase.vo.CaseTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yujie
 * @data 2023/4/22 20:46
 */
@Api(tags = "预案类型")
@RestController
@RequestMapping("/cas")
public class CaseTypeController {

    @Resource
    private CaseTypeService caseTypeService;

    @LogInfo
    @ApiOperation(value = "分页展示预案类型信息", notes = "分页展示预案类型信息")
    @GetMapping("/page")
    public CommonResult<CaseType> page(CaseTypeParam param) {
        Page<CaseTypeVO> caseTypeVOPage = caseTypeService.pageCaseType(param);
        return CommonResult.success(caseTypeVOPage);
    }

    @LogInfo
    @ApiOperation(value = "根据id删除预案类型信息", notes = "根据id删除预案类型信息")
    @GetMapping("/delete")
    public CommonResult<CaseType> deleteCaseType(@RequestParam @ApiParam("预案类型id") Integer id) {
        caseTypeService.deleteById(id);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "添加预案类型信息", notes = "添加预案类型信息")
    @PostMapping("/add")
    public CommonResult<CaseType> addCaseType(CaseType caseType) {
        caseTypeService.insertCaseType(caseType);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "根据id查询预案类型信息", notes = "根据id查询预案类型信息")
    @GetMapping("/query")
    public CommonResult<CaseType> queryCaseType(@RequestParam @ApiParam("预案类型id") Integer id) {
        CaseType caseType = caseTypeService.selectById(id);
        return CommonResult.success(caseType);
    }

    @LogInfo
    @ApiOperation(value = "修改预案类型信息", notes = "修改预案类型信息")
    @PostMapping("/update")
    public CommonResult<CaseType> updateCaseType(CaseType caseType) {
        caseTypeService.updateCaseType(caseType);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "查询所有预案类型信息", notes = "查询所有预案类型信息")
    @GetMapping("/all")
    public CommonResult<CaseType> queryAllCaseType() {
        List<CaseType> caseTypes = caseTypeService.selectAll();
        return CommonResult.success(caseTypes);
    }
}
